﻿//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Linq;
//using System.Runtime.Remoting.Messaging;
//using System.Text;
//using System.Web;
//using NHibernate;

//namespace FT.Architecture.NHibernate.SessionManagement
//{
//    public class SessionProvider
//    {
//        #region Thread-safe, lazy Singleton

//        /// <summary>
//        /// This is a thread-safe, lazy singleton.  See http://www.yoda.arachsys.com/csharp/singleton.html
//        /// for more details about its implementation.
//        /// </summary>
//        public static SessionProvider Instance {
//            get {
//                return Nested.SessionProvider;
//            }
//        }

//        /// <summary>
//        /// Private constructor to enforce singleton
//        /// </summary>
//        private SessionProvider() { }

//        /// <summary>
//        /// Assists with ensuring thread-safe, lazy singleton
//        /// </summary>
//        private class Nested
//        {
//            internal static readonly SessionProvider SessionProvider =
//                new SessionProvider();
//        }

//        #endregion

//        public ISession ProvideSession(string configPath)
//        {
//            NHibernateSessionManagerOld.Instance.
//            return (ISession)sessions[configPath];
//        }

//        public void DiscardSession()
//        {
            
//        }

//        private bool IsInWebContext()
//        {
//            return HttpContext.Current != null;
//        }

//        private readonly Hashtable _sessionFactories = new Hashtable();
//        private const string TRANSACTION_KEY = "CONTEXT_TRANSACTIONS";
//        private const string SESSION_KEY = "CONTEXT_SESSIONS";

//        /// <summary>
//        /// Since multiple databases may be in use, there may be one session per database 
//        /// persisted at any one time.  The easiest way to store them is via a hashtable
//        /// with the key being tied to session factory.  If within a web context, this uses
//        /// <see cref="HttpContext" /> instead of the WinForms specific <see cref="CallContext" />.  
//        /// Discussion concerning this found at http://forum.springframework.net/showthread.php?t=572
//        /// </summary>
//        private Hashtable ContextSessions
//        {
//            get
//            {
//                if (IsInWebContext())
//                {
//                    if (HttpContext.Current.Items[SESSION_KEY] == null)
//                        HttpContext.Current.Items[SESSION_KEY] = new Hashtable();

//                    return (Hashtable)HttpContext.Current.Items[SESSION_KEY];
//                }

//                if (CallContext.GetData(SESSION_KEY) == null)
//                    CallContext.SetData(SESSION_KEY, new Hashtable());

//                return (Hashtable)CallContext.GetData(SESSION_KEY);
//            }
//        }
//    }
//}
